home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 September / EnigmA AMIGA RUN 10 (1996)(G.R. Edizioni)(IT)[!][issue 1996-09][EARSAN CD XI].iso / aweb / awebftp.rexx < prev    next >
OS/2 REXX Batch file  |  1996-03-31  |  5KB  |  166 lines

  1. /* AwebFTP FTP plug-in
  2.  
  3.     Version 1.0e
  4.  
  5.     By Josef Faulkner (panther@gate.net) IRC: Josef
  6.  
  7.     Description:
  8.     ¯¯¯¯¯¯¯¯¯¯¯¯
  9.     This plugin will allow you to do inline FTPing of files on the net,
  10.     without the need to call an external FTP program (except FTPMount, which
  11.     is transparent).  It will distinguish between a directory and a file, and
  12.     act accordingly.
  13.  
  14.     Features:
  15.     ¯¯¯¯¯¯¯¯¯
  16.         o Fast reaction, since FTPMount does a lot of cacheing of dirs
  17.         o Asyncronous download (thanks to Aweb), you can continue browsing
  18.           while it downloads, and Aweb will inform you when the transfer
  19.           has completed!
  20.         o Brings up a requestor to ask what you want to save as
  21.  
  22.     Requirements:
  23.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  24.     FTPMount version 8 must be installed and running (version 7 wont work)
  25.         available on Aminet:
  26.         FTPMount-0.8.lha   comm/tcp   109K Mounts FTP sites
  27.  
  28.     Installation:
  29.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  30.     1) Put this script in the same directory that the Aweb executable is in.
  31.     2) Set Aweb to the following settings:
  32.       ----------------------------------------------
  33.         Network 3: External Programs
  34.                    ftp:
  35.           Command:  sys:rexxc/rx
  36.         Arguments:  awebftp.rexx %s %s %s  <--- *** NOTE different in this vers ***
  37.       ----------------------------------------------
  38.     3) Set your preferences for this script below:
  39.  
  40.     Known Bugs:
  41.     ¯¯¯¯¯¯¯¯¯¯¯
  42.     FTPMount has a bug with some linked directories.  ftp://ftp.netcom.com/ is
  43.     an example of this.  If you know how to solve this problem, let me know :)
  44. */
  45.  
  46. savedir='RAM:'  /* Default directory to download to */
  47.  
  48. if ~show('L','rexxsupport.library') then if ~addlib('rexxsupport.library',0,-30,0) then exit 20
  49. vers='1.0e'
  50. parse arg server' 'file' 'screen
  51. if server='about' then do
  52.     
  53. end
  54. else do
  55.     if right(server,1)~='/' then server=server'/'
  56.     if length(file)>0 then do
  57.         filebk=file
  58.         dir=''
  59.         do until index(filebk,'/')=0
  60.             parse var filebk dirbk'/'filebk
  61.             dir=dir||dirbk'/'
  62.         end
  63.         file=filebk
  64.         url='ftp://'server||dir||file
  65.     end
  66.     else url='ftp://'server
  67.     address command 'delete t:awebftp#? >NIL:'
  68.     tmpfile='t:awebftp'time(S)'.html'
  69.     if exists(url) then do
  70.         info=statef(url)
  71.         type=word(info,1)
  72.         size=word(info,2)
  73.         select
  74.             when type='DIR' then do
  75.                 address command 'list 'url' lformat "%n %l %d" >t:awebftp.tmp'
  76.                 call open(1,'t:awebftp.tmp',r)
  77.                 call open(2,tmpfile,w)
  78.                 call writeln(2,'<html><head><title>'url'</title></head><body><pre>')
  79.                 call writeln(2,'<h2>Directory of 'url'</h2>')
  80.                 call writeln(2,'<hr>Size        Name                       Date<hr>')
  81.                 do until eof(1)
  82.                     text=readln(1)
  83.                     if strip(text)~='' then do
  84.                         parse var text fname' 'size' 'date
  85.                         if right(url,1)~='/' then url=url'/'
  86.                         lurl=url||fname
  87.                         if length(fname)>25 then ename=left(fname,25)||'</a>'
  88.                         else ename=fname||'</a>'
  89.                         if upper(word(text,2))='DIR' then do
  90.                             call writeln(2,right(size,10)'  <a href="'lurl'">'left(ename,30,' ')||right(date,10))
  91.                         end
  92.                         else do
  93.                             call writeln(2,left(size,10)'  <a href="'lurl'">'left(ename,30,' ')||right(date,10))
  94.                         end
  95.                     end
  96.                 end
  97.                 call writeln(2,'</pre><hr>AwebFTP v'vers' by <a href="mailto:panther@gate.net">Josef Faulkner</a>.')
  98.                 call writeln(2,'</body></html>')
  99.                 call close(1)
  100.                 call close(2)
  101.                 address AWEB.1 'open file://localhost/'tmpfile
  102.             end
  103.             when type='FILE' then do
  104.                 if open(11,url,r) then do
  105.                     call close(11)
  106.                     address command 'requestchoice "AWebFTP" "View or Save 'file'?" "View|Save|Cancel" pubscreen="'screen'" >t:awebftpchoice.tmp'
  107.                     call open(1,'t:awebftpchoice.tmp',r)
  108.                     text=readln(1)
  109.                     call close(1)
  110.                     select
  111.                         when text=0 then do
  112.                             call putawebmsg('Transfer aborted.')
  113.                         end
  114.                         when text=1 then do
  115.                             call putawebmsg('Downloading 'url' to view in Aweb.')
  116.                             address command 'copy 'url' 'tmpfile
  117.                             address AWEB.1 'open file://localhost/'tmpfile
  118.                         end
  119.                         when text=2 then do
  120.                             address command 'requestfile drawer='savedir' file='file' pubscreen='screen' >'tmpfile
  121.                             call open(1,tmpfile,r)
  122.                             text=readln(1)
  123.                             call close(1)
  124.                             if left(text,7)~='no more' then do
  125.                                 call putawebmsg('Downloading 'file' ('size' bytes).<br> You may resume using Aweb, and a message will appear when transfer is complete.')
  126.                                 address command 'copy 'url' 'text
  127.                                 call putawebmsg('Download of 'file' to 'text' complete.')
  128.                             end
  129.                             else do
  130.                                 call putawebmsg('Transfer aborted.')
  131.                             end
  132.                         end
  133.                         otherwise do
  134.                             call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #2-'text)
  135.                             exit
  136.                         end
  137.                     end
  138.                 end
  139.                 else do
  140.                     call putawebmsg('Sorry, could not open 'url' for read access.')
  141.                 end
  142.             end
  143.             otherwise do
  144.                 putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #1-'type)
  145.                 exit
  146.             end
  147.         end
  148.     end
  149.     else do
  150.         call putawebmsg('Sorry, 'url' doesn''t exist.')
  151.     end
  152. end
  153. exit
  154.  
  155. PUTAWEBMSG: procedure
  156. parse arg text
  157.     address command 'delete t:awebmsg#?.html >NIL:'
  158.     fname='t:awebmsg'time(S)'.html'
  159.     call open(4,fname,w)
  160.     call writeln(4,'<html><head><title>AwebFTP Message</title></head><body>')
  161.     call writeln(4,'<h3>'text'</h3>')
  162.     call writeln(4,'</body>')
  163.     call close(4)
  164.     address AWEB.1 'OPEN file://localhost/'fname
  165. return
  166.